<!-- html  4 
  -->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>

        let age1 = 18;

        //数组
        // let ages = new Array(10)
        let ages = [10, 20, 18, 19, 22, 18, 20]


        //访问数组
        console.log("ages", ages);
        //通过下标访问元素
        console.log("ages[0] ", ages[0]);
        // console.log("ages[1] ",ages[1]);
        // console.log("ages[2] ",ages[2]);
        // console.log("ages[3] ",ages[3]);
        // console.log("ages[4] ",ages[4]);
        // console.log("ages[5] ",ages[5]);
        // console.log("ages[6] ",ages[6]);

        //属性 length   
        console.log(" ages.length", ages.length);



        //数组的遍历
        for (let i = 0; i < ages.length; i++) {
            console.log("通过 length 遍历： ages[" + i + "] ", ages[i]);
        }

        //修改数据
        ages[3] = 100

        //数组的遍历
        for (let i = 0; i < ages.length; i++) {
            console.log("修改之后 遍历 ", ages[i]);
        }


        //数组是可变长的        Java   c  数组是不可变长的（定长）
        //修改数据
        ages[50] = 500;

        //属性 length   
        console.log("  ages[50] = 500   ,  ages", ages);



        //数组中的元素 类型不固定 可以不一样
        // int ages[] = {10,20,30,"啊啊啊啊啊啊"}   Java 中数组类型固定
        let arrays = [10, 20, "jshand", true, null]

        console.log("  arrays", arrays);


        //使用常量定义数组
        let names = ["张飞", "刘备"]

        // names[names.length] = "关羽"

        //数组对象 的函数
        names.push("关羽")
        console.log("  names", names);

        names.push("诸葛亮")
        console.log("  names", names);

        names.unshift("赵云")
        console.log("  names", names);

        let last = names.pop();
        console.log("  names.pop()", last);
        console.log("   names", names);

        let first = names.shift();
        console.log("  names.shift()", first);
        console.log("   names", names);



        //reverse
        console.log("   names.reverse()", names);



        //拼接字符串
        
        console.log("   names.join(\"###\") ", names.join("###"));







    </script>
</head>

<body>




</body>

</html>